package JUC.线程池.队无界;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 池固定1 队列无界
 */
public class UseSinglePool {
    public static void main(String[] args) {
        useSinglePol();
    }
    private static void useSinglePol() {
        ExecutorService executorService = Executors.newSingleThreadExecutor();
        // start 异步 同时 塞入 多个 ？ -> x 错！ -> 只能塞入一个
        for (int i = 0; i < 5; i++) {
            executorService.submit(()->{
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

                System.out.println(Thread.currentThread().getName());
            });
        }
        executorService.shutdown();
    }
}
/**
 * 同时 只能 塞入 1个 只能塞入一个
 * pool-1-thread-1
 * 1s
 * pool-1-thread-1
 * 1s
 * pool-1-thread-1
 * 1s
 * pool-1-thread-1
 * 1s
 * pool-1-thread-1
 */